package com.toolkit.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ExecutorConfig {


    @Bean
    public Executor avicOrgUserTaskExecutor(){
        ThreadPoolTaskExecutor threadPoolExecutor = new ThreadPoolTaskExecutor();
        threadPoolExecutor.setCorePoolSize(1);//核心线程数
        threadPoolExecutor.setMaxPoolSize(10);//最大线程数
        threadPoolExecutor.setQueueCapacity(5000);//队列容量
        threadPoolExecutor.setThreadNamePrefix("avicOrgUserTaskExecutor-");//队列名称
        threadPoolExecutor.setWaitForTasksToCompleteOnShutdown(true);
        threadPoolExecutor.setKeepAliveSeconds(60);
        threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return threadPoolExecutor;
    }
}
